package com.candicom.race.cars;

class Mercedes extends AbstractCar {

    private final double topSpeed = 100;
    private final double acceleration = 2;
    private final int turningSensitivity = 3;

    Mercedes() throws Exception {
        super(CarModel.MERCEDES, "mercedes.png");
    }

    @Override
    public void speedUp() {
        if (speed + acceleration > topSpeed) {
            speed = topSpeed;
        } else {
            speed += acceleration;            
        }
    }

    @Override
    public void slowDown() {
        if (speed - (acceleration / 2) < 0) {
            speed = 0;
        } else {
            speed -= (acceleration / 2);
        }
    }

    @Override
    public void turnRight() {
        angle = (angle + turningSensitivity) % 360;
        // assistant module, slows down when turning
        turnAssist();
    }

    @Override
    public void turnLeft() {
        angle = (360 + angle - turningSensitivity) % 360;
        // assistant module, slows down when turning
        turnAssist();
    }

    private void turnAssist() {
        if(speed < 10){
            return;
        }
        if (speed - (acceleration / 1.99999999) < 0) {
            speed = 0;
        } else {
            speed -= (acceleration / 1.99999999);
        }
    }
}
